package mapper

import (
	"gin-epg/internal/app/dao"
	"gin-epg/internal/app/entity"
)

// CreateEpgProgramSync 创建一个新的 EpgProgramSync
func CreateEpgProgramSync(epgProgramSync *entity.EpgProgramSync) (err error) {
	if err = dao.SqlSession.Create(epgProgramSync).Error; err != nil {
		return err
	}
	return
}

/*
* 获取 EpgProgramSync 集合
 */
func GetAllEpgProgramSync() (epgProgramSyncList []*entity.EpgProgramSync, err error) {
	if err := dao.SqlSession.Find(&epgProgramSyncList).Error; err != nil {
		return nil, err
	}
	return
}

/*
* 根据 id 删除 EpgProgramSync
 */
func DeleteEpgProgramSyncById(id string) (err error) {
	err = dao.SqlSession.Where("id=?", id).Delete(&entity.EpgProgramSync{}).Error
	return
}

/*
* 根据 id 查询 EpgProgramSync
 */
func GetEpgProgramSyncById(id string) (epgProgramSync *entity.EpgProgramSync, err error) {
	// 初始化 epgProgram 变量
	epgProgramSync = new(entity.EpgProgramSync)

	// 执行查询
	if err = dao.SqlSession.Where("id=?", id).First(epgProgramSync).Error; err != nil {
		return nil, err
	}
	return epgProgramSync, nil
}

/*
* 更新 EpgProgramSync 信息
 */
func UpdateEpgProgramSync(epgProgramSync *entity.EpgProgramSync) (err error) {
	err = dao.SqlSession.Save(epgProgramSync).Error
	return
}
